import 'package:flutter/material.dart';
import 'package:flutter1911/bean/detail_goods_bean_result.dart';
import 'package:flutter1911/page/detail/detail_bottom.dart';
import 'package:flutter1911/page/detail/detail_tab_bar.dart';
import 'package:flutter1911/page/detail/detail_top.dart';
import 'package:flutter1911/provider/detai_iInfo_provider.dart';
import 'package:flutter1911/service/service.dart';
import 'package:provider/provider.dart';

class DetailsPage extends StatelessWidget {
  final String goodsId;

  const DetailsPage({Key? key, required this.goodsId}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    _getBackInfo(context, goodsId);
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          icon: const Icon(Icons.arrow_back_ios),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
        title: const Text('商品详情'),
      ),
      body: Stack(
        children: [
          ListView(
            children: const [DetailTop(), DetailTabBar()],
          ),
          const Positioned(
            child: DetailBottom(),
            bottom: 0,
            left: 0,
          )
        ],
      ),
    );
  }

  void _getBackInfo(BuildContext context, id) async {
    request('getGoodsDetail', id).then((value) {
      // print(value);
      Provider.of<DetailInfoProvider>(context, listen: false)
          .setGoodsInfo(DetailGoodsBeanResult.fromJson(value).data);
    });
  }
}
